package com.example.order.controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;
import java.util.Map;

@SuppressWarnings("SpringJavaAutowiringInspection")
@RestController
@RequestMapping("/user")
public class customerController {

    @Autowired
    JdbcTemplate jdbcTemplate;

    @PostMapping("/")
    public String cust_order()
    {
        return "顾客下单,发送给服务人员";
    }

    @GetMapping("/")
    public String order_success()
    {
        return "顾客收到反馈，下单成功";
    }

        //账户验证
        @RequestMapping(value="/login",method= RequestMethod.POST)
        public String login(@RequestParam String username,@RequestParam String password){
            return "接收的账号:"+username+",密码:"+password;
        }
        //根据姓氏查询用户列表信息
        @RequestMapping(value="/query")
        public String queryUsers(@RequestParam(value="uname",required = false,defaultValue = "张") String userName){
            return "参数："+userName;
        }
        //根据id查询用户详情
        @RequestMapping(value="/detail/{userID}",method= RequestMethod.GET)
        public String queryDetail(@PathVariable String userID){
            return "接收到的参数是："+userID;
        }

        //查询user表中所有数据返回到前端页面
        @GetMapping("/get_testtable")
        public List<Map<String,Object>> userList(){
            String sql="select * from testtable";
            List<Map<String, Object>> user_List = jdbcTemplate.queryForList(sql);
            return user_List;
        }

        @GetMapping("/get_test")
        public List<Map<String,Object>> user(){
            String sql="select id from testtable where name='李四'";
            List<Map<String, Object>> list_maps = jdbcTemplate.queryForList(sql);
            return list_maps;

        }

}
